<?php
// +----------------------------------------------------------------------
// | Copyright (c) 2012 HongPing All rights reserved.
// +----------------------------------------------------------------------
// | ActionName:业务单据处理模块
// +----------------------------------------------------------------------
// | Author: HongPing <hongping626@qq.com>
// +----------------------------------------------------------------------

class OrdermainAction extends CommonAction {
	function _filter(&$map){
        //$map['id'] = array('egt',2);
        if($_POST['selectname']){
            $map['ordernumber|invoicenumber|remarks'] = array('like',"%".$_POST['selectname']."%");
        }
		
        if($_POST['ordertype']){
        $map['ordertype'] = $_POST['ordertype'];
        }
        $createU = $_SESSION[C('USER_AUTH_KEY')];
        if($createU!='1'){
         $map['createuser'] = $_SESSION[C('USER_AUTH_KEY')];//如果非管理员则只能操作自己创建的单据
        }
        if($_POST['dealstatus']){
          $orderStatus = $_POST['dealstatus'];
          if($orderStatus==1){
            $map['stkstatus'] = 0 ;
          }else if($orderStatus==2){
            $map['paystatus'] = 0 ;
          }else if($orderStatus==3){
            $map['stkstatus&paystatus'] = 1 ;
          }
        }else{
          $orderStatus = 0; 
        }
	 }
    
    
    //删除单据
    function delOrders(){        
       $arrData = $_REQUEST['ids'];
       $countArr = count($arrData);
       
       $mainModel = D('Ordermain');
       $detailModel = D('Orderdetails'); 
       $countDel = 0;
       
       for($i=0;$i<$countArr;$i++){
          $ids = '';
          $orderNumber ='';
          unset($where);
         if($arrData[$i]){
          $ids = $arrData[$i];
          $orderNumber = getTableColVal($ids,'Ordermain','ordernumber');
          $where['ordernumber'] = $orderNumber;
          $LockStatus = $mainModel->where($where)->getField('status');
          if($LockStatus==0){
            $dealStatus = $mainModel->where($where)->getField('dealstatus');
             if($dealStatus==0){
               $mainModel->where($where)->delete();//删除总表信息
               $detailModel->where($where)->delete();//删除详细表信息
               $countDel=$countDel+1;
             }else{
                $this->error('发现单据:'.$orderNumber.'为已处理，本次处理过程终止。');exit;
             }             
          }else{
            $this->error('发现单据:'.$orderNumber.'已被锁定，本次处理过程终止。');exit;
          }
         }
       } 
       $this->success('成功删除 '.$countDel.' 个单据。');
   }  
   
//处理单据
function doDealOder(){
    $arrData = $_REQUEST['ids'];
    $countArr = count($arrData);
    
    $mainModel = D('Ordermain');//初始化总单据表
    $detailModel = D('Orderdetails'); 
    $Stocks = D('Stocks');
    $banks = D('Bankaccount');  
    $countDel = 0;
    for($i=0;$i<$countArr;$i++){
        $ids = '';
        $whId='';
        $orderNumber ='';
        $BankAmount = 0;
        $OrderAmount = 0;
        $upAmount = 0;
        unset($where);
        if($arrData[$i]){
            $ids = $arrData[$i];//获取单据ID
            $orderNumber = getTableColVal($ids,'Ordermain','ordernumber');//根据ID获取单据编号
            $where['ordernumber'] = $orderNumber;//设置查询总单据条件
            $mainList = $mainModel->where($where)->find();//查询单据总信息
            $whId = $mainList['warehouse'];//设置操作库位          
            $detailList = $detailModel->where($where)->select();//查询单据产品详细信息
            //$stocksList = $detailModel->where($where)->select();//查询当前产品库存信息
            $sumNums = 0;
            $sumOnums = $mainList['ordernums'];//单据操作数量总数
            for($m=0;$m<count($detailList);$m++){
            unset($whereC);$stknums = 0;
            $whereC['prodid'] = $detailList[$m]['prodid'];
            $stknums = $Stocks->where($whereC)->getField('stocknums');
            if(!$stknums){$stknums = 0;}
                $sumNums = $sumNums + $stknums;//当前库存量
            }
            
            $bankid = $mainList['bankid'];//单据要操作的账户
            $mapBank['id'] = $bankid;//账户查询条件
            $BankAmount = $banks->where($mapBank)->getField('bamount');//查询帐号余额
            $OrderAmount = $mainList['payamount'];//单据实际需付金额
                     
            //库存不足异常
            if($mainList['ordertype']==2 or $mainList['ordertype']==3){
                if(bccomp($sumNums,$sumOnums) < 0){
                    $this->error('库存不足,终止处理过程。'.$sumOnums.'/'.$sumNums);exit;  
                }
            }
            
            //账户金额不足异常
           if($mainList['ordertype']==1 or $mainList['ordertype']==4){//判断付款单
            if( bccomp($BankAmount,$OrderAmount)<0  ){//账户余额小于付款额
              $this->error('账户余额不足,终止处理过程。'.$BankAmount .'<'. $OrderAmount);exit;  
            }
           }
            $LockStatus = ''; 
            $LockStatus = $mainModel->where($where)->getField('status');
            if($LockStatus==0){//未锁定
                $dealStatus='';
                $dealStatus = $mainModel->where($where)->getField('dealstatus');
                if($dealStatus==0){//未处理
                  if($mainList['ordertype']==2 or $mainList['ordertype']==3){
                      $upAmount = $BankAmount + $OrderAmount;//增加账户金额
                  }else if($mainList['ordertype']==1 or $mainList['ordertype']==4){
                      $upAmount = $BankAmount - $OrderAmount;//减少账户余额
                  }else{
                      $upAmount = $BankAmount;//不加减
                  }
                  if($banks->where($mapBank)->setField('bamount',$upAmount) or $mainList['ordertype']==5){//如果更新成功则进行库存加减                  
                    //如果有库存则进一步操作
                    for($j=0;$j<count($detailList);$j++){//循环单据下的所有产品信息
                        $stkwhere['prodid'] = $detailList[$j]['prodid'];
                        $stkwhere['warehid'] = $whId;
                        if($Stocks->where($stkwhere)->getField('id')){//如果库存中已经有这个商品则更新数量
                            $addNums = $detailList[$j]['ordernums'];//操作库存的数量
                            if($detailList[$j]['iotype']==1){//入库
                                $Stocks->where($stkwhere)->setInc('stocknums',$addNums);//增加库存量
                            }else if($detailList[$j]['iotype']==2){//出库
                                $Stocks->where($stkwhere)->setDec('stocknums',$addNums);//减少库存量
                            }
                            $Stocks->where($stkwhere)->setField('updatetime',strtotime(date('Y-m-d H:i:s')));//更新时间
                        }else{
                            if($detailList[$j]['iotype']==1){//入库
                                $insertD['prodid'] = $detailList[$j]['prodid'];
                                $insertD['stocknums'] = $detailList[$j]['ordernums'];
                                $insertD['prodprice'] = $detailList[$j]['orderprice'];
                                $insertD['warehid'] = $whId;                
                                $insertD['updatetime'] =strtotime(date('Y-m-d H:i:s'));
                                $Stocks->add($insertD);//增加新产品库存
                            }else if($detailList[$j]['iotype']==2){//出库
                                $this->error('未发现该商品库存,终止处理过程。');exit;
                            }
                        }                        
                      }
                    
                    $countDel=$countDel+1;
                    $mainModel->where($where)->setField('dealstatus',1);//设置单据状态为已处理
                    $mainModel->where($where)->setField('dealtime',strtotime(date('Y-m-d H:i:s')));//设置单据处理时间
                    
                  }else{$this->error($OrderAmount.'单据:'.$orderNumber.'账户金额操作异常，本次处理过程终止。'.$banks->getLastSql());exit;}
                }else{$this->error('发现单据:'.$orderNumber.'为已处理，本次处理过程终止。');exit;}             
            }else{$this->error('发现单据:'.$orderNumber.'已被锁定，本次处理过程终止。');exit;}          
        
        }
    } 
    if($countDel>0){
      $this->success('成功处理 '.$countDel.' 个单据。');  
    }else{
      $this->success('处理单据失败。');
    }
    
}
   
   //打印单据画面
   function printOrder(){
    $orderNumber = getTableColVal($_REQUEST['orderId'],'Ordermain','ordernumber');
    
    $mainModel = D('Ordermain');//初始化总单据表
    $detailModel = D('Orderdetails');
    $NullM = M();        
    $map['ordernumber'] = $orderNumber;
    
    $mainList = $mainModel->where($map)->find();
    $detailSql = 'SELECT a.ordersort, a.prodcode, b.prodname, b.prodsize, b.pmaterial, b.unit, a.ordernums, a.orderprice, a.discounts, a.totalamount
    FROM hp_orderdetails AS a, hp_products AS b
    WHERE a.prodid = b.id
    AND ordernumber = \''.$orderNumber.'\'
    ORDER BY a.ordersort ASC';    
    $detailList = $NullM->query($detailSql);
   // $echoSql = $NullM->getLastSql();    
    //dump($echoSql);
    
    $this->assign ( 'detailList', $detailList);    
    $this->assign ( 'mainList', $mainList);
    $this->assign ( 'orderNumber', $orderNumber);
    
    $this->display();
   }
   //导出单据信息到Excel
   function  exportExcel(){
        /*先查出数据,后引入PHPExcel可以避免ThinkPHP和PHPExcel冲突 HongPing**/
        $orderNumber = $_REQUEST['orderNum'];
        
        $map['ordernumber'] = $orderNumber;//设置条件
        $ordersTable = D('Ordermain');//单据信息
        $detailTable = D('Orderdetails');//详细信息
        
        $ordersList = $ordersTable->where($map)->find();
        $detailList = $detailTable->where($map)->select();
        
        vendor("PHPExcel.PHPExcel");
        $objPHPExcel = new PHPExcel();
        
        $excelTitle = $orderNumber;
        $excelTitle1 = "厦门俱佳工贸有限公司";
        $excelTitle2 = getOrdertype($ordersList['ordertype']);
        $excelTitle3 = "地址:厦门象屿五金机电城12-14　　电话:0592-8873605  　　传真:0592-6215929";
        
        $objPHPExcel->getActiveSheet()->setShowGridlines(false);//不显示网格

        
        if($ordersList['ordertype']==1 or $ordersList['ordertype']==4){
            $trueValue1 = '应付金额：';
            $trueValue2 = '实付金额：';             
        }
        
        if($ordersList['ordertype']==2 or $ordersList['ordertype']==3){
            $trueValue1 = '应收金额：';
            $trueValue2 = '实收金额：';   
        }
        
        $trueValue = $trueValue1.$ordersList['orderamount'].'        '.$trueValue2.$ordersList['payamount'].'        '.'折扣金额：'.$ordersList['oddamount'];
        
               
        $objPHPExcel->getActiveSheet()->mergeCells('A1:K1');//合并单元格
        $objPHPExcel->getActiveSheet()->mergeCells('A2:K2');//合并单元格
        $objPHPExcel->getActiveSheet()->mergeCells('A3:K3');//合并单元格
        $objPHPExcel->getActiveSheet()->mergeCells('A4:G4');//合并单元格
        $objPHPExcel->getActiveSheet()->mergeCells('H4:K4');//合并单元格
        $objPHPExcel->getActiveSheet()->mergeCells('A5:G5');//合并单元格
        $objPHPExcel->getActiveSheet()->mergeCells('H5:K5');//合并单元格
        
        $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true)->setSize(18);
        $objPHPExcel->getActiveSheet()->getStyle('A2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('A2')->getFont()->setSize(16);
        $objPHPExcel->getActiveSheet()->getStyle('A3')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('A4')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
        $objPHPExcel->getActiveSheet()->getStyle('A5')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
        $objPHPExcel->getActiveSheet()->getStyle('H4')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
        $objPHPExcel->getActiveSheet()->getStyle('H5')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
        

        $objPHPExcel->setActiveSheetIndex(0)  
            ->setCellValue('A1', $excelTitle1)
            ->setCellValue('A2', $excelTitle2)  
            ->setCellValue('A3', $excelTitle3) 
            ->setCellValue('A4', '客 户：'.getTableColVal($ordersList['contactid'],'Contacts','comname'))
            ->setCellValue('H4', '单据编号：'.$orderNumber)
            ->setCellValue('A5', '摘 要：'.$ordersList['remarks'])
            ->setCellValue('H5', '单据日期：'.date('Y 年 m 月 d 日',$ordersList['ordertime']))     
            ->setCellValue('A6', '编 号') 
            ->setCellValue('B6', '料 号')  
            ->setCellValue('C6', '名 称')  
            ->setCellValue('D6', '规 格')  
            ->setCellValue('E6', '材 质')  
            ->setCellValue('F6', '单 位')  
            ->setCellValue('G6', '数 量')  
            ->setCellValue('H6', '单 价(￥)')  
            ->setCellValue('I6', '折 扣(%)')  
            ->setCellValue('J6', '金 额(￥)')
            ->setCellValue('K6', '备 注');
        $objPHPExcel->getActiveSheet()->getStyle('A6')->getFont()->setBold(true);
        $objPHPExcel->getActiveSheet()->getStyle('B6')->getFont()->setBold(true);
        $objPHPExcel->getActiveSheet()->getStyle('C6')->getFont()->setBold(true);
        $objPHPExcel->getActiveSheet()->getStyle('D6')->getFont()->setBold(true);
        $objPHPExcel->getActiveSheet()->getStyle('E6')->getFont()->setBold(true);
        $objPHPExcel->getActiveSheet()->getStyle('F6')->getFont()->setBold(true);
        $objPHPExcel->getActiveSheet()->getStyle('G6')->getFont()->setBold(true);
        $objPHPExcel->getActiveSheet()->getStyle('H6')->getFont()->setBold(true);
        $objPHPExcel->getActiveSheet()->getStyle('I6')->getFont()->setBold(true);
        $objPHPExcel->getActiveSheet()->getStyle('J6')->getFont()->setBold(true);
        $objPHPExcel->getActiveSheet()->getStyle('K6')->getFont()->setBold(true);
        
        $objPHPExcel->getActiveSheet()->getStyle('A6')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('B6')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('C6')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('D6')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('E6')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('F6')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('G6')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('H6')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('I6')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('J6')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('K6')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        // Miscellaneous glyphs, UTF-8   
                       
        for($i=0;$i<count($detailList);$i++){
            $tempi = $i+7;//自加到第六行
            $objPHPExcel->getActiveSheet(0)->setCellValue('A'.$tempi, $detailList[$i]['ordersort']);  
            $objPHPExcel->getActiveSheet(0)->setCellValue('B'.$tempi, getTableColVal($detailList[$i]['prodid'],'Products','partnumber'));  
            $objPHPExcel->getActiveSheet(0)->setCellValue('C'.$tempi, getTableColVal($detailList[$i]['prodid'],'Products','prodname'));  
            $objPHPExcel->getActiveSheet(0)->setCellValue('D'.$tempi, getTableColVal($detailList[$i]['prodid'],'Products','prodsize'));             
            $objPHPExcel->getActiveSheet(0)->setCellValue('E'.$tempi, getTableColVal($detailList[$i]['prodid'],'Products','pmaterial'));  
            $objPHPExcel->getActiveSheet(0)->setCellValue('F'.$tempi, getTableColVal($detailList[$i]['prodid'],'Products','unit'));  
            $objPHPExcel->getActiveSheet(0)->setCellValue('G'.$tempi, $detailList[$i]['ordernums']);  
            $objPHPExcel->getActiveSheet(0)->setCellValue('H'.$tempi, $detailList[$i]['orderprice']);  
            $objPHPExcel->getActiveSheet(0)->setCellValue('I'.$tempi, $detailList[$i]['discounts']);  
            $objPHPExcel->getActiveSheet(0)->setCellValue('J'.$tempi, $detailList[$i]['totalamount']);
            $objPHPExcel->getActiveSheet(0)->setCellValue('K'.$tempi, $detailList[$i]['remarks']); 
            
            $objPHPExcel->getActiveSheet()->getStyle('A'.$tempi)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
            $objPHPExcel->getActiveSheet()->getStyle('B'.$tempi)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
            $objPHPExcel->getActiveSheet()->getStyle('C'.$tempi)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
            $objPHPExcel->getActiveSheet()->getStyle('D'.$tempi)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
            $objPHPExcel->getActiveSheet()->getStyle('E'.$tempi)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
            $objPHPExcel->getActiveSheet()->getStyle('F'.$tempi)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
            $objPHPExcel->getActiveSheet()->getStyle('G'.$tempi)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
            $objPHPExcel->getActiveSheet()->getStyle('H'.$tempi)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
            $objPHPExcel->getActiveSheet()->getStyle('I'.$tempi)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
            $objPHPExcel->getActiveSheet()->getStyle('J'.$tempi)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
            $objPHPExcel->getActiveSheet()->getStyle('K'.$tempi)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
            
        }
        //详细累计
        $tempi = $tempi+2;//空行下移
        $objPHPExcel->getActiveSheet()->mergeCells('A'.$tempi.':C'.$tempi);//合并单元格
        $objPHPExcel->setActiveSheetIndex(0) 
            ->setCellValue('A'.$tempi,'共计：') 
            ->setCellValue('G'.$tempi, $ordersList['ordernums'])
            ->setCellValue('J'.$tempi, $ordersList['orderamount']);
        //应收付  
        $tempi = $tempi +1;        
        $objPHPExcel->getActiveSheet()->mergeCells('A'.$tempi.':K'.$tempi);//合并单元格
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A'.$tempi,$trueValue);
        $objPHPExcel->getActiveSheet()->getStyle('A'.$tempi)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
        
        $staBorder = 'A6:'.'K'.$tempi;
        //单据操作人栏     
        $tempi = $tempi +1;        
        $objPHPExcel->getActiveSheet()->mergeCells('A'.$tempi.':K'.$tempi);//合并单元格
        //$objPHPExcel->getActiveSheet()->mergeCells('D'.$tempi.':F'.$tempi);//合并单元格
        //$objPHPExcel->getActiveSheet()->mergeCells('G'.$tempi.':I'.$tempi);//合并单元格
        //$objPHPExcel->getActiveSheet()->mergeCells('J'.$tempi.':K'.$tempi);//合并单元格
        $rowValue = '制单人：'.getTableColVal($ordersList['createuser'],'User','nickname').'                     '.
                    '经办人：'.getTableColVal($ordersList['orderuser'],'User','nickname').'                     '.
                    '送货人：'.'                     '.
                    '验收人：';
                
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A'.$tempi,$rowValue);
                    //->setCellValue('D'.$tempi,'')
                    //->setCellValue('G'.$tempi,'')
                    //->setCellValue('J'.$tempi,'');
        $objPHPExcel->getActiveSheet()->getStyle('A'.$tempi)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
        //$objPHPExcel->getActiveSheet()->getStyle('D'.$tempi)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
        //$objPHPExcel->getActiveSheet()->getStyle('G'.$tempi)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
        //$objPHPExcel->getActiveSheet()->getStyle('J'.$tempi)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
        
        
        //单据备注信息栏
        $tempi = $tempi +1;        
        $objPHPExcel->getActiveSheet()->mergeCells('A'.$tempi.':K'.$tempi);//合并单元格
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A'.$tempi,'(①白联:留底 ②红联:客户 ③黄联:会计)');
        $objPHPExcel->getActiveSheet()->getStyle('A'.$tempi)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        
        //对齐设置
        $objPHPExcel->getActiveSheet()->getStyle($staBorder)->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);


        
        
        
        // Rename sheet   
        $objPHPExcel->getActiveSheet()->setTitle($excelTitle);  
        // Set active sheet index to the first sheet, so Excel opens this as the first sheet   
        $objPHPExcel->setActiveSheetIndex(0);  
  
  
       //Redirect output to a client’s web browser (Excel5)  
        //header('Pragma:public');
        //header('Content-Type:application/vnd.ms-execl;name="'.$excelTitle.'.xls"');
      //  header('Content-Disposition:inline;filename="'.$excelTitle.'('.date('Ymd-His').').xls"');
        
      // header('Content-Type: application/vnd.ms-excel');  
     //  header('Content-Disposition: attachment;filename="'.$excelTitle.'('.date('Ymd-His').').xls"');  
      // header('Cache-Control: max-age=0');
      // header('cache-control:must-revalidate');
        header('pragma:public');
        header('X-UA-Compatible:IE=7');      
        header('Content-type:application/vnd.ms-excel;charset=gbk;name="'.$excelTitle.'.xls"');
        header("Content-Disposition:inline;filename=$excelTitle.xls");
        //header("Pragma:no-cache"); 
  
        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');  
        $objWriter->save('php://output'); 
        exit;
       // $this->display();       
        
    }
 
}
?>